#include <stdio.h>
#include <math.h>

const int CityInfoLen=2;
const int MaxCityNum=100;
const int PointNum=4;


//判断3个构成的角是否90度  角123
int jsAngle(int x1,int y1,int x2,int y2,int x3,int y3){
    int num=(x1-x2)*(x2-x3)+(y1-y2)*(y2-y3);
    return num==0?1:0;
}

/**
 * 计算城市的第四个点
 * */
void getPoint4(int * point1,int* point2,int* point3,int * point4)
{
    if(jsAngle(point1[0],point1[1],point2[0],point2[1],point3[0],point3[1]))
    {
        point4[0]=(point1[0]+point3[0])-point2[0];
        point4[1]=(point1[1]+point3[1])-point2[1];
    }
    else if(jsAngle(point1[0],point1[1],point3[0],point3[1],point2[0],point2[1]))
    {
        point4[0]=(point1[0]+point2[0])-point3[0];
        point4[1]=(point1[1]+point2[1])-point3[1];
    }
    else{
        point4[0]=(point3[0]+point2[0])-point1[0];
        point4[1]=(point3[1]+point2[1])-point1[1];
    }
}

float distance(int * point1,int* point2){
    return sqrt((point1[0]-point2[0])*(point1[0]-point2[0])+(point1[1]-point2[1])*(point1[1]-point2[1]));
}

float min(float d1,float d2)
{
    return d1>d2?d2:d1;
}


void printArray(float priceArray[MaxCityNum*PointNum][MaxCityNum*PointNum],int len)
{
    for(int i=0;i<len;i++)
    {
        for(int j=0;j<len;j++)
        {
            printf("%.1f\t",priceArray[i][j]);
        }
        printf("\n");
    }
    printf("\n");

}


int main(){
    int n,s,t,a,b;
    scanf("%d",&n);
    int i,j,k,l;

    int cityInfoArray[MaxCityNum*PointNum][CityInfoLen];
    int cityPrice[MaxCityNum];
    float path[MaxCityNum*PointNum][MaxCityNum*PointNum];
    for(int o=0;o<n;o++)
    {
        scanf("%d %d %d %d",&s,&t,&a,&b);
        
        k=0;
        for(i=0;i<s;i++)
        {
            for(j=0;j<3;j++)
            {
                scanf("%d %d",&cityInfoArray[k+j][0],&cityInfoArray[k+j][1]);
            }
            scanf("%d",&cityPrice[i]);
            
            //找出城市第四个点
            getPoint4(cityInfoArray[k],cityInfoArray[k+1],cityInfoArray[k+2],cityInfoArray[k+3]);
            k+=4;
        }


        //计算点与点之间的直线距离
        int num=s*PointNum;
        for(i=0;i<num;i++)
        {
            path[i][i]=0;
            int city1=i/PointNum;
            for(j=i+1;j<num;j++)
            {
                int city2=j/PointNum;
                float d=distance(cityInfoArray[i],cityInfoArray[j]);
                float p=t;
                if(city1==city2)
                {
                    p=cityPrice[city1];
                }
                float price=p*d;
                path[i][j]=price;
                path[j][i]=price; 
            }
        }

        // printArray(path,num);
        for(k=0;k<num;k++)
        {
            for(i=0;i<num;i++)
            {
                for(j=0;j<num;j++)
                {
                    if(i==j)
                    {
                        continue;
                    }

                    float m=path[i][k]+path[k][j];
                    if(m<path[i][j])
                    {
                        path[i][j]=m;
                    }
                }
            }
        }

        // printArray(path,num);

        float min=1e15;
        for(i=0;i<PointNum;i++)
        {
            for(j=0;j<PointNum;j++)
            {
                k=a*PointNum+i-PointNum;
                l=b*PointNum+j-PointNum;
                if(min>path[k][l])
                {
                    min=path[k][l];
                }
            }
        }
        printf("%.1f\n",min);
    }
    return 0;
}